addLoadEvent(initAd);
addLoadEvent(hideSiteMap);

var RSSPath="Feed.xhtml?Bid=18";
var LINKPath="detail.xhtml?Bid=18";

var nHangNo = (Math.floor((Math.random()) * 1000) % 5) + 1;
var nSecondHangNo = 0;
var isHangSecondCheck = 0;

var nHangInterval = 8000;
var nHangNoOld = nHangNo;
var objHanger;

///crl add variable;
var objHangerTimer;
var objHangerOldHeight;
var maxHangerHeight=400;
var minHangerHeight=200;

function hideSiteMap(){
    $("sitemap").style.display="none";
}

function initAd(){
    var xmlHttp=new ajax.$x(RSSPath,"GET",getXMLHander,null,"",null,false);
}
function getXMLHander(){
  var xmlDoc=this.req.responseXML.documentElement;
  var items=$as.call(xmlDoc,"item");
  for(var i=0;i<=5;i++){//items.length
    var dis=$a.call(items[i],"description");
    dis=dis.lastChild.nodeValue;
    
    aHtmls.push(dis);
  }
  
    objHanger = $("divHanger");
    objHanger.style.height=minHangerHeight+"px";
    objHanger.onmouseover=overHander;
    objHanger.onmouseout=outHander;
    objHanger.onclick=function(){document.location=LINKPath};
    rotateHanger();
}

function overHander(){
    $a.call(this,"img").style.filter="";
    objHangerTimer=setTimeout(overInterval,10);
    clearTimeout(nRotateTimer);
}
function overInterval(){
    clearTimeout(objHangerTimer);
    
    var obj=objHanger;
    if(parseInt(obj.style.height)<maxHangerHeight){
        obj.style.height=parseInt(obj.style.height)+10+"px";
        objHangerTimer=setTimeout(overInterval,10);
    }
}
function outInterval(){
    clearTimeout(objHangerTimer);
    
    var obj=objHanger;
    if(parseInt(obj.style.height)>minHangerHeight){
        obj.style.height=parseInt(obj.style.height)-10+"px";
        objHangerTimer=setTimeout(outInterval,10);
    }
}


function outHander(){
    $a.call(this,"img").style.filter="gray";
    objHangerTimer=setTimeout(outInterval,10);
    restartRotate();
}
				
var aHtmls = new Array ();

function bulidImgHTML(src,href){
    href=href||"###";
    return "<a href='"+href+"' onfocus='this.blur()' target='self'><img src='"+src+"' border=0></a>"
    
}
				
function getNavigatorType() 
{
	if (navigator.appName == "Microsoft Internet Explorer") return 1;  
	else if (navigator.appName == "Netscape") return 2;	
	else return 0;
}


function rotateHanger()
{
				
	if (getNavigatorType() == 1) {
		objHanger.filters[0].apply();
		setHanger();
		objHanger.filters[0].play();
		
	} else {
		setHanger();
	}
				
	nHangNoOld = nHangNo;
	if (isHangSecondCheck == 0) {
		nHangNo = nSecondHangNo;
		isHangSecondCheck = 1;
	} else {
		(nHangNo==(aHtmls.length-1))?nHangNo=0:nHangNo++;
	}
				/**/
				
	nRotateTimer = setTimeout('rotateHanger()',nHangInterval);
}

function restartRotate()
{  
	(nHangNo==(aHtmls.length-1))?nHangNo=0:nHangNo++;
				
	nRotateTimer = setTimeout('rotateHanger()',nHangInterval);
}
				
function changeHanger(nGotoNo)
{
	nHangNo = nGotoNo;
				
	if (getNavigatorType() == 1) {
		objHanger.filters[0].apply();
		setHanger();
		objHanger.filters[0].play();
		
	} else {
		setHanger();
	}
				
}

function setHanger()
{			
	objHanger.innerHTML=aHtmls[nHangNo];
	$a.call(objHanger,"img").style.filter="gray";
}